<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="/gtimp/css/pay/index.css" rel="stylesheet" type="text/css"/>
    <link href="/gtimp/css/pay/submitOrder.css" rel="stylesheet" type="text/css"/>
    <link href="/gtimp/css/jw/jw.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="/gtimp/js/jquery/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="/gtimp/js/hint/jquery.hint.js"></script>
    <script type="text/javascript" src="/gtimp/js/jquery/jquery.json-2.2.js"></script>
    <script type="text/javascript" src="/gtimp/js/jw/jw.js"></script>
    <script type="text/javascript" src="/gtimp/js/pay/mousewheel.js"></script>
    <script type="text/javascript" src="/gtimp/js/pay/easyscroll.js"></script>
    <script type="text/javascript" src="/gtimp/js/pay/scrollInit.js"></script>
    <script type="text/javascript">
        var interval;
        $(document).ready(function () {

            //初始化总费用
            countSumFree();
            $(":checkbox.accountCheckbox").on("click", function () {
                var type = this.name;
                var id = this.value;
                var price = $("#" + type + "_" + id).val();
                var old = $("#free_" + id).val();
                if (this.checked) {
                    old = Number(old) + Number(price);
                } else {
                    old = Number(old) - Number(price);
                }
                $("#free_" + id).val(old);
                countSumFree();
            });
        });

        /*
         *	统计总费用
         */
        function countSumFree() {
            var frees = $("input[id^='free_']");
            var sum = 0;
            for (var i = 0; i < frees.length; i++) {
                var f = frees[i];
                sum += Number(f.value);
            }
            $("#sum_free").val(sum);
        }
        function submitOrder() {
            $("#orderForm").submit();
            $("#submitBtm").attr("disabled", "disabled");
            interval = setInterval('queryPayment()', 3000);
            jw.confirm('<div><p style="font-style: normal;font-size: 16px;color:red;">请到新页面完成支付，完成支付后点击 确定</p></div>', function () {
                window.location = 'declaration-main?declaraState=DS00';
            }, function () {
                window.location = 'declaration-main?declaraState=DS00';
            });
        }

        function queryPayment() {
            $.ajax({
                url: "payAbcAction-getPayId?declareStr=" + $("input[name='declaration_ids']").val(),
                success: function (data) {
                    var d = $.parseJSON(data);
                    if (d.msg == 'success') {
                        $.ajax({
                            url: "payAbcAction-queryAbcPayMentStatus?pay_id=" + d.id,
                            success: function (data) {
                                var k = $.parseJSON(data);
                                if (k.msg == 'success') {
                                    window.clearInterval(interval);
                                    window.open("payAbcAction-payAbcSuccess?pay_id=" + k.id, '_blank');
                                    window.location = 'declaration-main?declaraState=DS00';
                                }
                            }
                        });
                    }
                }
            });
        }
    </script>
    <title>报关报检业务（提交订单）</title>
</head>
<body>
<div class="container">
    <div class="tab">
        <div class="active">提交订单</div>
        <div>在线支付</div>
        <div>支付完成</div>
    </div>
    <div class="clear"></div>
    <form id="orderForm" action="declaration-confirmPay" target="_blank">
        <div class="orderBox">
            <div class="spare">
                <div class="orderDetails">
                    <div class="thead">
                        <div>序号</div>
                        <div>订单号</div>
                        <div>价格</div>
                    </div>

                    <div class="tbodyDetails">
                        <div class="div_scroll">
                            <div class="div_scroll0">
                                <table>
                                    <s:iterator id="declaration" value="#request.declarations" status='st'>
                                        <tr>
                                            <td><s:property value='#st.index+1'/></td>
                                            <input type="hidden" name="declaration_ids" value="${declaration.id}">
                                            <td>${declaration.businessId}</td>
                                            <td><input type="text" id="free_${declaration.id}"
                                                       value="${declaration.declaration_free}" disabled/></td>
                                        </tr>
                                        <%-- 		    		<input type="checkbox" class="accountCheckbox" name="clearance_ids" value="${declaration.id}" />现场办通关单
                                                                <input  type="hidden" id="clearance_ids_${declaration.id}"
                                                                value="${declaration.declarationFreeDetail.inner_inspection-declaration.declarationFreeDetail.outter_inspection}" />
                                                                <input type="checkbox" class="accountCheckbox" name="steaming_ids" value="${declaration.id}" />现场办熏蒸
                                                                <input  type="hidden" id="steaming_ids_${declaration.id}"
                                                                value="${declaration.declarationFreeDetail.steaming_base+declaration.container_num * declaration.declarationFreeDetail.steaming_container}" />
                                                                <input type="checkbox" class="accountCheckbox" name="mmf_ids" value="${declaration.id}" />市场购买家私
                                                                <input  type="hidden" id="mmf_ids_${declaration.id}" value="${declaration.container_num *declaration.declarationFreeDetail.mmf_free}" /> --%>
                                    </s:iterator>
                                </table>
                            </div>
                        </div>
                    </div>
                    <div class="totals">
                        <div class="amount">总计：&nbsp;&nbsp;<input id="sum_free" name="sum_free" value=""
                                                                  readonly="readonly"></div>
                    </div>
                    <div>
                        <button type="button" id="submitBtm" class="submit" onclick="submitOrder()">提交订单</button>
                        <!--   <a href="#" class="submit" onclick="" >提交订单</a> -->
                    </div>
                </div>
            </div>
        </div>
        <form/>
</div>
</body>
</html>
